Module DEPRECIATED
    Private Sub fExportCurrentMap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fExportCurrentMap.Click
        saveCar.Title = "Select or Enter the filename to Export to"
        saveCar.Filter = "*.bin Binary |*.bin"
        If saveCar.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Try
                Dim fStream As New FileStream(saveCar.FileName, FileMode.OpenOrCreate)
                Dim bStream As New BinaryWriter(fStream)
                bStream.Write(m_ptArray)
                bStream.Close()
                fStream.Close()
                Err_message("Bin File Exported : " & saveCar.FileName)
            Catch ex As Exception
            End Try
        Else
            Err_message("Export Operation Cancelled")
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If tmrGraph.Enabled = True Then tmrGraph.Enabled = False Else tmrGraph.Enabled = True
        Dim f_ints() As Integer = {2944, 2945, 2946, 2988}
        m_EmulatorLog = New EmulatorLog(5888, 16, 16, True)
        m_EmulatorLog.addRange(f_ints)
        ' dGrid_Paint(dGrid, Nothing)
        dGrid.Invalidate()
        Threading.Thread.Sleep(1000)
        'dGrid.Refresh()

        Dim f_ints2() As Integer = {2945, 2946, 2955, 2956}
        m_EmulatorLog.addRange(f_ints2)
        dGrid.Invalidate()
        'dGrid_Paint(dGrid, Nothing)
    End Sub
    Private Sub dGrid_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles dGrid.Paint, bGrid.Paint
        Try
            'dGrid_PreInvalidate(sender)
            'If IsNothing(e) Then
            'dGrid_DrawTrace(sender)
            Debug.Print("Painting")
            Exit Try
            'sender.TraceDraw()
            'sender.TraceDraw()
            Using b As SolidBrush = _
                                   New SolidBrush(dGrid.RowHeadersDefaultCellStyle.ForeColor)
                e.Graphics.DrawString( _
                m_ptTable.getWidthScale.Description.ToolTip, _
                New System.Drawing.Font("Courier New", 7), _
                b, _
                16, _
                0)
            End Using
            Using b As SolidBrush = _
                                   New SolidBrush(dGrid.RowHeadersDefaultCellStyle.ForeColor)
                e.Graphics.DrawString( _
                m_ptTable.getHeightScale.Description.ToolTip, _
                New System.Drawing.Font("Courier New", 7), _
                b, _
                0, _
                8)
            End Using
        Catch
            'Err_message("error displaying emulator/Consult trace")
        End Try
    End Sub
    Private Sub dGrid_DrawTrace(ByRef Grid As Controls.libGrid)
        Dim f_tag As TraceTag = CType(Grid.Tag, TraceTag)
        Dim f_clr As New Color()
        If Not IsNothing(f_tag) Then
            'Debug.Print("Drawing Trace")
            If f_tag.TrcX >= 0 Or f_tag.TrcY >= 0 Then
                Dim f_tmX As Double = f_tag.TrcX
                Dim f_tmY As Double = f_tag.TrcY
                If f_tmX = -1 Then f_tmX = 0
                If f_tmY = -1 Then f_tmY = 0
                Grid.CreateGraphics.DrawRectangle(New Pen(Color.FromArgb(GetRegistryKey("colour_Trace"))), New Rectangle((f_tmX * Grid.Item(0, 0).Size.Width) + Grid.RowHeadersWidth, (f_tmY * Grid.Item(0, 0).Size.Height) + Grid.ColumnHeadersHeight, Grid.Item(0, 0).Size.Width, Grid.Item(0, 0).Size.Height))
            End If
            If Not IsNothing(f_tag.EmuX) And Not IsNothing(f_tag.EmuY) Then
                If f_tag.EmuX.Length >= 1 And f_tag.EmuX.Length = f_tag.EmuY.Length Then
                    For i As Int16 = 0 To UBound(f_tag.EmuX)
                        Grid.CreateGraphics.DrawRectangle(New Pen(Color.FromArgb(GetRegistryKey("colour_Emulator"))), New Rectangle(f_tag.EmuX(i) * Grid.Item(0, 0).Size.Width + Grid.RowHeadersWidth, f_tag.EmuY(i) * Grid.Item(0, 0).Size.Height + Grid.ColumnHeadersHeight, Grid.Item(0, 0).Size.Width, Grid.Item(0, 0).Size.Height))
                    Next
                End If
            End If
        End If
    End Sub
    Private Sub dGrid_PreInvalidate(ByRef Grid As Controls.libGrid)
        Dim f_tag As TraceTag = CType(Grid.Tag, TraceTag)
        If Not IsNothing(f_tag) Then
            Debug.Print("Pre Painting")
            Dim f_x As Double = f_tag.TrcX
            Dim f_y As Double = f_tag.TrcY
            If f_x >= 0 Or f_y >= 0 Then
                If f_x < 0 Then f_x = 0
                If f_y < 0 Then f_y = 0
                Debug.Print("x: " & f_x)
                Debug.Print("y: " & f_y)
                Grid.Invalidate(New Rectangle(f_x * Grid.Item(0, 0).Size.Width + Grid.RowHeadersWidth - 1, f_y * Grid.Item(0, 0).Size.Height + Grid.ColumnHeadersHeight - 1, Grid.Item(0, 0).Size.Width + 3, Grid.Item(0, 0).Size.Height + 3))
            End If

            If Not IsNothing(f_tag.EmuX) And Not IsNothing(f_tag.EmuY) Then
                If f_tag.EmuX.Length >= 1 And f_tag.EmuX.Length = f_tag.EmuY.Length Then
                    For i As Int16 = 0 To UBound(f_tag.EmuX)
                        Grid.Invalidate(New Rectangle(f_tag.EmuX(i) * Grid.Item(0, 0).Size.Width + Grid.RowHeadersWidth - 1, f_tag.EmuY(i) * Grid.Item(0, 0).Size.Height + Grid.ColumnHeadersHeight - 1, Grid.Item(0, 0).Size.Width + 3, Grid.Item(0, 0).Size.Height + 3))
                    Next
                End If
            End If
        End If
    End Sub
    Public Sub getTable(ByRef Array() As Byte, ByRef Grid As Controls.libGrid, ByRef Graph As Controls.libGrid, ByRef lb As Label)
        Try
            If Not IsNothing(Array) Then
                Dim f_width As Integer = Grid.ColumnCount
                Dim f_height As Integer = Grid.RowCount
                Dim f_SelGrid(f_width - 1, f_height - 1) As Boolean

                Try
                    For Each f_cell As DataGridViewCell In Grid.SelectedCells
                        f_SelGrid(f_cell.ColumnIndex, f_cell.RowIndex) = True
                    Next
                Catch ex As Exception
                End Try

                Dim f_min As Integer = graphMin(Grid)
                Dim f_max As Integer = graphMax(Grid)
                Dim elemNo As Integer

                With Graph

                    .ClearGraph()
                    .ZGridNumber = -1
                    .XGridNumber = -1
                    .YGridNumber = 6
                    .XGridColor = Color.Black
                    .ZGridColor = Color.Black
                    .YGridColor = Color.Black
                    .BackColor = Color.Black
                    .TrackMode = 2
                    .AddElement()
                    .Projection = 1
                    .set_ElementPointColor(0, RGB(128, 55, 64))
                    .set_ElementPointSize(0, 8)
                    .set_ElementLineColor(0, RGB(64, 0, 64))
                    .set_ElementLineWidth(0, 6)
                    .set_ElementType(0, 3)
                    elemNo = 0
                    .SetLightCoordinates(0, 128, 200, 5000)
                    Dim f_selFound As Boolean = False
                    '###########
                    '## Colums! ie, accross TP
                    If f_height >= 2 Then
                        For x As Integer = 0 To f_width - 1
                            For y As Integer = 0 To f_height - 2

                                .AddElement()
                                elemNo += 1
                                .set_ElementType(elemNo, 2)
                                .SetLightCoordinates(elemNo, 128, 200, 5000)
                                .set_ElementSurfaceFill(elemNo, 64)
                                ' .set_Lighting(elemNo, 64)
                                .set_ElementLightingAmbient(elemNo, 128)
                                .set_ElementLightingDiffuse(elemNo, 128)
                                .set_ElementLightingSpecular(elemNo, 128)
                                .set_ElementPointColor(elemNo, RGB(128, 128, 128))
                                f_selFound = False

                                If f_SelGrid(x, y) Or f_SelGrid(x, y + 1) Then
                                    f_selFound = True
                                End If

                                If Not f_selFound Then
                                    .set_ElementLineColor(elemNo, RGB(Grid(x, y).Style.BackColor.R, Grid(x, y).Style.BackColor.G, Grid(x, y).Style.BackColor.B))
                                    .set_ElementLineWidth(elemNo, 1)
                                    .set_ElementPointSize(elemNo, 2)
                                    GoTo PastSet
                                End If

                                .set_ElementLineColor(elemNo, RGB(255, 255, 254))
                                .set_ElementPointSize(elemNo, 3)
                                .set_ElementLineWidth(elemNo, 2)
pastSet:
                                .set_ElementSurfaceFill(elemNo, 64)
                                .set_ElementSurfaceFlat(elemNo, 64)
                                .set_ElementMaterialAmbient(elemNo, 128)
                                .set_ElementMaterialDiffuse(elemNo, 128)
                                .set_ElementMaterialEmission(elemNo, 64)
                                .set_ElementMaterialShinines(elemNo, 128)
                                .set_ElementMaterialSpecular(elemNo, 128)




                                If f_height = 1 Or f_width = 1 Then
                                    .PlotXYZ((y), Me.Min, (-x), elemNo)
                                End If
                                .PlotXYZ((y), Grid.Item(x, y).Value, (-x), elemNo)
                                .PlotXYZ((y + 1), Grid.Item(x, y + 1).Value, (-x), elemNo)
                                If f_width = 1 And y = f_height - 2 Then
                                    .PlotXYZ((y + 1), Me.Min, (-x), elemNo)
                                End If
                            Next
                        Next
                    End If
                    If f_width >= 2 Then
                        For y As Integer = 0 To f_height - 1
                            For x As Integer = 0 To f_width - 2
                                .AddElement()
                                elemNo += 1
                                .set_ElementType(elemNo, 2)
                                .SetLightCoordinates(elemNo, 128, 200, 5000)
                                .set_ElementSurfaceFill(elemNo, 64)
                                '.set_Lighting(elemNo, 64)
                                .set_ElementLightingAmbient(elemNo, 128)
                                .set_ElementLightingDiffuse(elemNo, 128)
                                .set_ElementLightingSpecular(elemNo, 128)
                                .set_ElementPointColor(elemNo, RGB(128, 128, 128))
                                f_selFound = False

                                If f_SelGrid(x, y) Or f_SelGrid(x + 1, y) Then f_selFound = True

                                If Not f_selFound Then
                                    .set_ElementLineColor(elemNo, RGB(Grid(x, y).Style.BackColor.R, Grid(x, y).Style.BackColor.G, Grid(x, y).Style.BackColor.B))
                                    .set_ElementLineWidth(elemNo, 1)
                                    .set_ElementPointSize(elemNo, 2)
                                    GoTo PastSet2
                                End If

                                .set_ElementLineColor(elemNo, RGB(255, 255, 254))
                                .set_ElementPointSize(elemNo, 3)
                                .set_ElementLineWidth(elemNo, 2)
pastSet2:
                                .set_ElementSurfaceFill(elemNo, 64)
                                .set_ElementSurfaceFlat(elemNo, 64)
                                .set_ElementMaterialAmbient(elemNo, 128)
                                .set_ElementMaterialDiffuse(elemNo, 128)
                                .set_ElementMaterialEmission(elemNo, 64)
                                .set_ElementMaterialShinines(elemNo, 128)
                                .set_ElementMaterialSpecular(elemNo, 128)

                                If f_height = 1 Or f_width = 1 Then
                                    .PlotXYZ((y), Me.Min, (-x), elemNo)
                                End If
                                .PlotXYZ((y), Grid.Item(x, y).Value, (-x), elemNo)
                                .PlotXYZ((y), Grid.Item(x + 1, y).Value, (-x - 1), elemNo)
                                If f_height = 1 And x = (f_width - 2) Then
                                    .PlotXYZ((y), Me.Min, (-x - 1), elemNo)
                                End If
                            Next
                        Next
                    End If

                    If f_width >= 2 And f_height >= 2 Then
                        .SetRange(0, f_height, Me.Min - 1, Me.Max + 1, -f_width, 0)
                    ElseIf f_width = 1 Then
                        Debug.Print("setting with small width")
                        .SetRange(0, f_height, Me.Min - 1, Me.Max + 2, -1, -1)
                    ElseIf f_height = 1 Then
                        Debug.Print("setting with small height")
                        .SetRange(-0.5, 0.5, Me.Min - 1, Me.Max + 1, -f_width, 0)
                    End If
skip:
                End With
            End If
        Catch
            Err_message("Error Displaying Graph")
        End Try
    End Sub

End Module
